#pragma once
#ifndef GRAPHICS_CAMERAENTITY_H
#define GRAPHICS_CAMERAENTITY_H
//------------------------------------------------------------------------------
/**
    @class Graphics::CameraEntity
  
    Represents a camera attached to a graphics stage. Any number of
    cameras can be attached to a stage.
    
    (C) 2007 Radon Labs GmbH
*/    
#include "graphics/graphicsentity.h"

//------------------------------------------------------------------------------
namespace Graphics
{
class CameraEntity : public GraphicsEntity
{
    DeclareClass(CameraEntity);
public:
    /// constructor
    CameraEntity();
    /// destructor
    virtual ~CameraEntity();

    /// compute clip status against bounding box
    virtual Math::ClipStatus::Type ComputeClipStatus(const Math::bbox& box);

    /// set projection matrix
    void SetProjTransform(const Math::matrix44& proj);
    /// get projection matrix
    const Math::matrix44& GetProjTransform() const;
    /// get view transform (inverse transform)
    const Math::matrix44& GetViewTransform() const;
    /// set new angle of view if it differs from current and update projection matrix
    void SetAngleOfView(float fov);
    /// set near clip plane if it differs from current and update projection matrix
    void SetNearClipPlane(float nearPlane);
    /// set far clip plane if it differs from current and update projection matrix
    void SetFarClipPlane(float farPlane);
    /// get near clip plane
    float GetNearClipPlane() const;
    /// get far clip plane
    float GetFarClipPlane() const;

protected:
    /// called when transform matrix changed
    virtual void OnTransformChanged();
    /// update the view projection matrix
    void UpdateViewProjMatrix();
    /// update proj matrix
    void UpdateProjMatrix();

    Math::matrix44 projMatrix;
    Math::matrix44 viewMatrix;
    Math::matrix44 viewProjMatrix;
    bool viewProjDirty;
    float angleOfView;
    float nearClipPlane;
    float farClipPlane;
};

//------------------------------------------------------------------------------
/**
*/
inline void
CameraEntity::SetProjTransform(const Math::matrix44& proj)
{
    this->projMatrix = proj;
    this->viewProjDirty = true;
}

//------------------------------------------------------------------------------
/**
*/
inline const Math::matrix44&
CameraEntity::GetProjTransform() const
{
    return this->projMatrix;
}

//------------------------------------------------------------------------------
/**
*/
inline const Math::matrix44&
CameraEntity::GetViewTransform() const
{
    return this->viewMatrix;
}

//------------------------------------------------------------------------------
/**
*/
inline float 
CameraEntity::GetNearClipPlane() const
{
    return this->nearClipPlane;
}

//------------------------------------------------------------------------------
/**
*/
inline float 
CameraEntity::GetFarClipPlane() const
{
    return this->farClipPlane;
}
} // namespace Graphics
//------------------------------------------------------------------------------
#endif
